package com.gibs.peixunapi.controller;

import com.gibs.peixunapi.enums.ResultEnum;
import com.gibs.peixunapi.result.Result;
import com.gibs.peixunapi.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;

import java.util.ArrayList;

/**
 * @author liangjiawei
 * @date 2020/08/20/19:59
 * @Version 1.0
 * @Description:
 */
@Slf4j
public class Application {

    Result getResult(BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            ArrayList<String> errorList = new ArrayList<String>();
            bindingResult.getAllErrors().forEach((objectError ->
                    errorList.add(objectError.getObjectName()+"\n"+objectError.getDefaultMessage())));
            log.error(String.valueOf(errorList));
            return ResultUtil.error(ResultEnum.UNKONW_ERROR, errorList);
        }
        return null;
    }
}
